package com.yueya.api.feedback;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.yueya.basic.feedback.model.Feedback;
import com.yueya.common.constant.CodeConst;
import com.yueya.common.model.Resp;
import com.yueya.common.service.BaseService;
import com.yueya.common.util.DateUtil;
import com.yueya.common.util.UUIDGenerator;

import net.sf.json.JSONObject;

public class IFeedbackService extends BaseService {

	// 增加反馈意见
	@Before(Tx.class)
	public Resp save(JSONObject jo, String userId) {

		if (containsKey(jo,  "content")) {

			String content = jo.getString("content");

			Feedback model = new Feedback();
			model.set("id", UUIDGenerator.getUUID()).set("user_id", userId)
					.set("content", content).set("create_time", DateUtil.getDate(DateUtil.timeFormat));

			boolean bl = model.save();
			if (bl) {
				resp.setCode(CodeConst.SUCCESS);
				resp.setMsg("add feedback success");
			} else {
				resp.setCode("20301");
				resp.setMsg("add feedback fail");
			}
		} else {
			resp.setCode(CodeConst.JSONFORMAT_WRONG);
			resp.setMsg("JSON参数不合法");
		}

		return resp;
	}

}